<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>客户管理</title>
<link th:href="@{/css/style.css}" rel="stylesheet" type="text/css" />
<script type="text/javascript" th:src="@{/js/jquery.js}"></script>
<script type="text/javascript">
function deltipOpen(data) {
  $("#isDeleteOrderId").val(data);

	$("#deltip").fadeIn(200);
}
function deltipClose() {
	$("#deltip").fadeOut(200);
}
function examinetipOpen(data) {
  $("#fenPeiOrderId").val(data);
	$("#examinetip").fadeIn(200);
}
function examinetipclose() {
	$("#examinetip").fadeOut(200);
}
</script>
</head>

<body>
<div class="place"> <span>位置：</span>
  <ul class="placeul">
    <li>营销管理</li>
    <li>订购单管理</li>
    <li>基本内容</li>
  </ul>
</div>
<div class="rightinfo">
  <form th:action="@{/order/queryfenye}" id="orderFrom" method="post">
    <ul class="tools">
      <li> 订单编号:
        <input name="orderid" th:value="${orderid==null?'':orderid}" type="text" />
      </li>
      <li> 客户姓名:
        <input name="customname" th:value="${customname==null?'':customname}" type="text" />
      </li>
      <li> 订购时间:
        <input name="startDate" class="startDate" th:value="${startDate==null?'':startDate}" type="text"  />-<input name="endDate" class="endDate" th:value="${endDate==null?'':endDate}" type="text" />
      </li>
      <li> 金额:
        <input type="text" id="minPrice" th:value="${minPrice==null?'':minPrice}" name="minPrice" class="stinput" />-<input type="text" th:value="${maxPrice==null?'':maxPrice}" id="maxPrice" name="maxPrice" class="stinput" />
      </li>
      <li> 审核状态：
        <select name="status">
          <option value="">请选择</option>
          <option th:selected="${status==null?false:status=='未审核'}" value="未审核">未审核</option>
          <option th:selected="${status==null?false:status=='审核中'}" value="审核中">审核中</option>
          <option th:selected="${status==null?false:status=='审核通过'}" value="审核通过">审核通过</option>
          <option th:selected="${status==null?false:status=='审核未通过'}" value="审核未通过">审核未通过</option>
        </select>
      </li>
      <li class="subBut" onclick="chaxun(1)"><img th:src="@{/images/t06.png}" />查询</li>
      <li class="subBut" ><a th:href="@{/order/toAdd}"><img th:src="@{/images/t01.png}" />添加</a></li>
    </ul>
    <table class="tablelist">
      <thead>
        <tr>
          <th>序号</th>
          <th>订单编号</th>
          <th>客户姓名</th>
          <th>联系电话</th>
          <th>订购时间</th>
          <th>金额</th>
          <th>操作人</th>
          <th>审核状态</th>
          <th>审核人</th>
          <th>审核时间</th>
          <th>操作</th>
        </tr>
      </thead>
      <tbody>
        <tr th:each="order:${session.orderPage.data}">
          <td th:text="${orderStat.count + (session.orderPage.pageNum - 1)*session.orderPage.pageSize }">1</td>
          <td th:text="${order.orderid}">DJ201701270001</td>
          <td th:text="${order.custom==null?'':order.custom.customname}">王金平</td>
          <td th:text="${order.custom==null?'':order.custom.telephone}">17370899727</td>
          <td th:text="${order.ordertime==null?'':#dates.format(order.ordertime,'yyyy-MM-dd HH:mm:ss')}">2017-01-25 15:05:05</td>
          <td><span th:with="num=1000" >￥[[${#numbers.formatInteger(order.ordermoney,1,'COMMA')}]]</span></td>
          <td th:text="${order.operatorUser==null?'':order.operatorUser.uname}">关羽</td>
          <td th:text="${order.status}">未审核</td>
          <td th:text="${order.checkUser==null?'':order.checkUser.uname}"></td>
          <td th:text="${order.chectime==null?'':#dates.format(order.chectime,'yyyy-MM-dd HH:mm:ss')}"></td>
          <td>
          	<a th:href="@{'/order/toshow?orderid='+${order.orderid}}" th:if="${order.status!='审核未通过'}" class="tablelink">查看详情</a>
            <a th:href="@{'/order/toupdate?orderid='+${order.orderid}}" th:if="${order.status!='审核中' && order.status!='审核通过'}" class="tablelink">修改</a>
            <a href="javascript:void(0);" class="tablelink" th:if="${order.status=='未审核'}"  th:onclick="deltipOpen([[${order.orderid}]])">删除</a>
            <a href="javascript:void(0);" class="tablelink" th:if="${order.status=='审核未通过' || order.status=='未审核'}" th:onclick="examinetipOpen([[${order.orderid}]])">提交审核</a>
            <a th:if="${order.ddState!=0}" th:href="@{'/order/toshow?orderid='+${order.orderid}}"  class="tablelink" >出库详情</a>
            </td>
        </tr>
      </tbody>
    </table>
    <div class="pagin">
      <input type="hidden" name="pageSize" th:value="${session.orderPage.pageSize}" />
      <input type="hidden" name="pageNum" id="pageNum"  th:value="${session.orderPage.pageNum}" />
      <div class="message">共<i class="blue" th:text="${session.orderPage.totalRows}">1256</i>条记录，当前显示第&nbsp;<i class="blue" th:text="${session.orderPage.pageNum}" >2&nbsp;</i>页</div>
      <!--总页数大于7页的时候-->
      <ul class="paginList" th:if="${session.orderPage.totalPage>7}">
        <li class="paginItem"><a href="javascript:;" th:onclick="lunbo([[${session.orderPage.pageNum==1?1:session.orderPage.pageNum-1}]])"><span class="pagepre"></span></a></li>
        <!--第一个格子-->
        <li th:class="${session.orderPage.pageNum==1?'paginItem current':'paginItem'}">
          <a href="javascript:;"  onclick="lunbo(1)">1</a>
        </li>

        <!--第二个格子-->
        <li class="paginItem" th:if="${(session.orderPage.pageNum>session.orderPage.totalPage-5) && (session.orderPage.pageNum>5)}"><a href="javascript:;">...</a></li>
        <li th:class="${session.orderPage.pageNum==2?'paginItem current':'paginItem'}" th:if="${(session.orderPage.pageNum<=5) || (session.orderPage.pageNum<=session.orderPage.totalPage-5 && session.orderPage.pageNum>5)}">
          <a href="javascript:;" onclick="lunbo(2)">2</a>
        </li>

        <!--第三个格子-->
        <li class="paginItem" th:if="${5<session.orderPage.pageNum && session.orderPage.pageNum<=(session.orderPage.totalPage-5)}"><a href="javascript:;" >...</a></li>
        <li th:class="${session.orderPage.pageNum==3?'paginItem current':'paginItem'}" th:if="${session.orderPage.pageNum<=5}"><a href="javascript:;" onclick="lunbo(3)">3</a></li>
        <li th:class="${session.orderPage.pageNum==(session.orderPage.totalPage-4)?'paginItem current':'paginItem'}" th:if="${(session.orderPage.pageNum>session.orderPage.totalPage-5) && (session.orderPage.pageNum>5)}"><a href="javascript:;" th:onclick="lunbo([[${session.orderPage.totalPage-4}]])" th:text="${session.orderPage.totalPage-4}" >6</a></li>

        <!--第四个格子-->
        <li th:class="${session.orderPage.pageNum==4?'paginItem current':'paginItem'}" th:if="${session.orderPage.pageNum<=5}"><a href="javascript:;" onclick="lunbo(4)">4</a></li>
        <li class="paginItem current" th:if="${5<session.orderPage.pageNum && session.orderPage.pageNum<=(session.orderPage.totalPage-5)}" ><a href="javascript:;" th:text="${session.orderPage.pageNum}"></a></li>
        <li th:class="${session.orderPage.pageNum==(session.orderPage.totalPage-3)?'paginItem current':'paginItem'}" th:if="${(session.orderPage.pageNum>session.orderPage.totalPage-5) && (session.orderPage.pageNum>5)}" ><a href="javascript:;" th:onclick="lunbo([[${session.orderPage.totalPage-3}]])" th:text="${session.orderPage.totalPage-3}">7</a></li>
        <!--第五个格子-->
        <li th:class="${session.orderPage.pageNum==5?'paginItem current':'paginItem'}" th:if="${session.orderPage.pageNum<=5}" ><a href="javascript:;" onclick="lunbo(5)">5</a></li>
        <li class="paginItem" th:if="${5<session.orderPage.pageNum && session.orderPage.pageNum<=(session.orderPage.totalPage-5)}"><a href="javascript:;" >...</a></li>
        <li th:class="${session.orderPage.pageNum==(session.orderPage.totalPage-2)?'paginItem current':'paginItem'}" th:if="${(session.orderPage.pageNum>session.orderPage.totalPage-5) && (session.orderPage.pageNum>5)}"><a href="javascript:;" th:onclick="lunbo([[${session.orderPage.totalPage-2}]])" th:text="${session.orderPage.totalPage-2}">4</a></li>
        <!--第六个格子-->
        <li class="paginItem" th:if="${session.orderPage.pageNum<=5}"><a href="javascript:;" >...</a></li>
        <li th:class="${session.orderPage.pageNum==(session.orderPage.totalPage-1)?'paginItem current':'paginItem'}" th:if="${session.orderPage.pageNum>5}"><a href="javascript:;" th:onclick="lunbo([[${session.orderPage.totalPage-1}]])" th:text="${session.orderPage.totalPage-1}">4</a></li>
        <!--第七个格子-->
        <li th:class="${session.orderPage.pageNum==session.orderPage.totalPage?'paginItem current':'paginItem'}"><a href="javascript:;" th:onclick="lunbo([[${session.orderPage.totalPage}]])" th:text="${session.orderPage.totalPage}">10</a></li>

        <!--        <li class="paginItem"><a href="javascript:;"><span class="pagenxt"></span></a></li>-->
        <li class="paginItem"><a href="javascript:;" th:onclick="lunbo([[${session.orderPage.pageNum==session.orderPage.totalPage?session.orderPage.totalPage:session.orderPage.pageNum+1}]])"><span class="pagenxt"></span></a></li>
      </ul>
      <!--总页数小于8页的时候-->
      <ul class="paginList" th:if="${session.orderPage.totalPage<=7}">
        <li class="paginItem"><a href="javascript:;" th:onclick="lunbo([[${session.orderPage.pageNum==1?1:session.orderPage.pageNum-1}]])"><span class="pagepre"></span></a></li>

        <li th:each="i:${#numbers.sequence(1,session.orderPage.totalPage)}" th:class="${i==session.orderPage.pageNum?'paginItem current':'paginItem'}">
          <a href="javascript:;" th:text="${i}" th:onclick="lunbo([[${i}]])"></a>
        </li>

        <li class="paginItem"><a href="javascript:;" th:onclick="lunbo([[${session.orderPage.pageNum==session.orderPage.totalPage?session.orderPage.totalPage:session.orderPage.pageNum+1}]])"><span class="pagenxt"></span></a></li>
      </ul>
    </div>
  </form>
  <!-- 删除提示框 -->
  <div id="deltip" class="tip">
    <input type="hidden" id="isDeleteOrderId" value="" />
    <div class="tiptop"><span>提示信息</span><a onclick="deltipClose()"></a></div>
    <div class="tipinfo"> <span><img th:src="@{/images/ticon.png}" /></span>
      <div class="tipright">
        <p>是否确认删除此条信息？</p>
        <cite>如果是请点击确定按钮 ，否则请点取消。</cite> </div>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" onclick="deleteOrder()" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="deltipClose()" />
    </div>
  </div>
  
  <!-- 审批提示框 -->
  <div id="examinetip" class="tip">
    <input type="hidden" id="fenPeiOrderId" value="" />
    <div class="tiptop">
    	<span>提示信息</span><a onclick="examinetipclose()"></a>
    </div>
    <div class="tipinfo1"> 
    	
        部门：
            <select class="dfselect">
                <option selected>市场部</option>
            </select>
			<p/>
            职位：
            <select class="dfselect" name="jobId" id="jobId">
            	<option value="">请选择</option>
                <option th:each="job:${session.jobList}" th:value="${job.jobId}" th:text="${job.jobName}">部门经理</option>
            </select>
   			<p/>
            姓名：
            <select class="dfselect" id="userList" name="checkid">
            	<option value="">请选择</option>
<!--                <option>刘备</option>-->
<!--                <option>曹操</option>-->
            </select>
			<p/>
    </div>
    <div class="tipbtn">
      <input name="" type="button"  class="sure" value="确定" onclick="toFenPei()" />
      &nbsp;
      <input name="" type="button"  class="cancel" value="取消" onclick="examinetipclose()" />
    </div>
  </div>
</div>
<script type="text/javascript">
	$('.tablelist tbody tr:odd').addClass('odd');

    $('.startDate').blur(function(){
      var startDate = $('.startDate').val();
      if(startDate != null && startDate != "") {
        if (!isDate(startDate)) {
          $('.startDate').val("");
          alert("格式错误，正确格式：2000-01-01");
        }
      }
    })
    $('.endDate').blur(function(){
      var endDate = $('.endDate').val();
      if(endDate != null && endDate != "") {
        if (!isDate(endDate)) {
          $('.endDate').val("");
          alert("格式错误，正确格式：2000-01-01");
        }
      }
    })

    function isDate(str) {
      var dateReg =  /^((([0-9]{3}[1-9]|[0-9]{2}[1-9][0-9]{1}|[0-9]{1}[1-9][0-9]{2}|[1-9][0-9]{3})-(((0[13578]|1[02])-(0[1-9]|[12][0-9]|3[01]))|((0[469]|11)-(0[1-9]|[12][0-9]|30))|(02-(0[1-9]|[1][0-9]|2[0-8]))))|((([0-9]{2})(0[48]|[2468][048]|[13579][26])|((0[48]|[2468][048]|[3579][26])00))-02-29))$/;
      return dateReg.test(str);
    }

    $('#minPrice').blur(function(){
      var minPrice = $('#minPrice').val();
      if(minPrice != null && minPrice != "") {
        if (!isMoney(minPrice)) {
          $('#minPrice').val("");
          alert("格式错误，正确格式：1000或1000.00");
        }
      }
    })
    $('#maxPrice').blur(function(){
      var maxPrice = $('#maxPrice').val();
      if(maxPrice != null && maxPrice != "") {
        if (!isMoney(maxPrice)) {
          $('#maxPrice').val("");
          alert("格式错误，正确格式：1000或1000.00");

        }
      }
    })

    function isMoney(str) {
      var moneyReg = /(^[1-9]([0-9]+)?(.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9].[0-9]([0-9])?$)/;
      return moneyReg.test(str);
    }





    function deleteOrder(){
      var isDeleteOrderId = $("#isDeleteOrderId").val();
      window.location.href="/order/todelete?orderid="+isDeleteOrderId;
    }

    function toFenPei(){
      var fenPeiOrderId = $("#fenPeiOrderId").val();
      var checkid = $("#userList").val();
      $.ajax({
        url: "/order/toFenPei",
        data: {"fenPeiOrderId": fenPeiOrderId,
          "checkid": checkid
        },
        dataType: "text",
        success:function (data){
          chaxun($("#pageNum").val());
        },
        error:function (){
          alert(222);
        }
      });
    }

    function chaxun(pageNum){
      $("#pageNum").val(pageNum);
      $("#orderFrom").submit();
    }
    function lunbo(pageNum){
      $("#pageNum").val(pageNum);
      $("#orderFrom").submit();
    }

    $("#jobId").change(function (){
      var jobId = $("#jobId").val();
      if(jobId != null && jobId != ""){
        $.ajax({
          url: "/custom/queryUsersListByAjax",
          data: {"jobId": jobId},
          dataType: "JSON",
          success:function (data){
            /*清空城市数据*/
            $("#userList").html("");
            var options = "<option value=''>请选择</option>";
            var arr=null;
            if(typeof data=='string')
              arr=JSON.parse(data);
            else
              arr=data;
            for(let i in arr){
              options += "<option value='"
                      + arr[i].uid
                      + "'>"
                      + arr[i].uname
                      + "</option>";
            }
            $("#userList").html(options);
          },
          error:function (){
            alert(222);
          }
        });
      }else {
        /*清空分配用户数据*/
        $("#userList").html("");
        var options = "<option value=''>请选择</option>";
        $("#userList").append(options);
      }
    });



</script>
</body>
</html>
